let app = getApp()
import {getEmployee} from "../../ajax/module/userInfo.js"
import imgUrl from "../../images/util.js"
import {filteremoji} from "../../utils/index.js"
Page({
  data:{
    CustomBar:app.globalData.CustomBar,
    scrollHeight:app.globalData.pageHeight - 60 -50,
    loading:false,
    pageNum: 0,
    pageSize: 10,
    phone:"",
    employeeList:[],
    dataNoneImg:imgUrl.dataNoneImg,
    femaleIcon:imgUrl.femaleIcon,
    maleIcon:imgUrl.maleIcon,
    isShow:true,

    id:""
  },
  onLoad(option){
      //  this.select()
     console.log(option)
     if(JSON.stringify(option) !== '{}'){
         this.setData({
           id:option.id
         })
     }
  },
  onShow(){
    this.onRefresh()
  },
  onRefresh(e){
    new Promise((resolve,reject)=>{
       this.setData({
         pageNum:0,
         employeeList:[]
       })
       resolve()
    }).then(res=>{
      this.select()
      this.setData({
        loading:false
      })
    }) 
  },
  inputPhone(e){
    this.setData({
      phone:filteremoji(e.detail.value) 
    })
  },
  jumpAdd(e){
    //  console.log(e.currentTarget.dataset.item)
     let {employeeName,employeePhone, gender,birthday,education,employeeId} =e.currentTarget.dataset.item
     app.globalData.newAddStaff={employeeName,employeePhone, gender,birthday,education,employeeId}

     if(this.data.id == ""){
      wx.navigateTo({
        url: '../add-staff/add-staff?id=1',
      })
     }else if(this.data.id == "1"){
      wx.navigateBack()
     }
    
  },
  selectByPhone(){
    new Promise((resolve,reject)=>{
      // console.log(this.data.phone)
      this.setData({
        pageNum:0,
        employeeList:[]
      })
      resolve()
    }).then(()=>{
      this.select()
    })
  },
  select(){
    new Promise((resolve,reject)=>{
      let pageNum=this.data.pageNum + 1 +""
      let pageSize=this.data.pageSize +""
      let queryParam=this.data.phone+""
      getEmployee({pageNum,pageSize,queryParam}).then(res=>{
        //  this.employeeList=res.data
        let newArr=this.data.employeeList.concat(res.data.rows)
        if(JSON.stringify(newArr) == "[]"){
          this.setData({
            isShow:true
          })
        }else{
          this.setData({
            isShow:false
          })
        }
         this.setData({
          employeeList:newArr
         })
         resolve(pageNum)
      })
     
    }).then(pageNum=>{
      this.setData({
        pageNum:Number(pageNum),
       
      })
    })
  },
  addStaff(){
    wx.navigateTo({
      url: '../add-staff/add-staff?id=2',
     
    })
  },
  onReachBottom(e){
    this.select()
  }
})